package com.lx.controller;

import com.lx.Exception.BusinessException;
import com.lx.Exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ProjectExceptionAdvice {
    // 全局异常处理 快速统一处理异常
    @ExceptionHandler(Exception.class)
    public Result doException(Exception e) {
        System.out.println("联系作者" + e.getMessage());
        return new Result(500, "系统繁忙", e.getMessage());
    }

    @ExceptionHandler(SystemException.class)
    public Result doSysException(SystemException e) {

        System.out.println(e.getMessage());
        return new Result(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(BusinessException.class)
    public Result doBusException(BusinessException e) {
        System.out.println("联系作者" + e.getMessage());
        return new Result(e.getCode(), " 系统繁忙 联系作者", e.getMessage());
    }
}
